import { create } from "zustand";

export interface ToastDataStore {
  show: boolean;
  title: string,
  descripion: string,
  duration?: number,
  type: 'success' | 'error' | 'warning' | 'info',
  
}

export interface ToastFnc {
  showToast: (opts: Omit<ToastDataStore, 'show'>) => void
}

export const useToastStore = create<ToastDataStore & ToastFnc>((set) => ({
  show: false,
  title: '错误',
  descripion: '发生了一个错误',
  duration: 1000,
  type: 'info',
  showToast: (opts) => {
    set({ show: true, ...opts  });
    setTimeout(() => {
      set({ show: false });
    }, opts.duration || 1000);
  },
}))

